home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / ixemul / include / ix.h < prev    next >
C/C++ Source or Header  |  1997-10-28  |  9KB  |  313 lines

  1. #ifndef __IX_H
  2. #define __IX_H
  3.  
  4. /* This header provides prototypes for ixemul specific functions and
  5.  * variables available in ixemul.library or libc.a.
  6.  *
  7.  * Each function is also documented in this header (or will be). Sometimes
  8.  * an ixemul extension is described here, but for ease of use the original
  9.  * prototype or macro is defined elsewhere.
  10.  */
  11.  
  12. /* Some forward declarations...
  13.  */
  14. struct Library;
  15. struct __res_state;
  16. struct timeval;
  17.  
  18.  
  19. /* This tells you which OS you are running on.
  20.  */
  21. extern int ix_os;
  22.  
  23. #define OS_IS_AMIGAOS   0
  24. #define OS_IS_POS       0x704F5300      /* 'pOS\0' */
  25.  
  26.  
  27. /* This is the name of the program without the path. E.g., if argv[0] is
  28.  * "/gg/bin/cat", then __progname is "cat".
  29.  */
  30. extern char *__progname;
  31.  
  32.  
  33. /* This macro can be ORed with the other flags you pass to open(). It will
  34.  * make the open() function case sensitive. This macro is defined in
  35.  * sys/fcntl.h.
  36.  *
  37.  * #define     O_CASE          0x1000
  38.  */
  39.  
  40.  
  41. /* Like vfork(), but the memory that the child allocates will be owned by
  42.  * the child. vfork() uses the parent's memory list, but since ix_vfork() is
  43.  * used as a fork() emulation, this would be undesirable, not in the least
  44.  * because that memory wouldn't be released until the parent exits. Causing
  45.  * a huge memory leak.
  46.  */
  47. int ix_vfork(void);
  48.  
  49.  
  50. /* This function is used to obtain and set variables from ixemul.library.
  51.  * In general, this is not a function you should call yourself.
  52.  * Only the startup code should use this. If you need to call this
  53.  * function for some reason, I recommend that the ix_get_variables()
  54.  * function from crt0.c is used instead (see below).
  55.  */
  56. void ix_get_vars(int argc, char **ctype, int *_sys_nerr, 
  57.               struct Library **sysbase, struct Library **dosbase,
  58.               FILE ***fpp, char ***environ_out, char ***environ_in,
  59.               int *real_errno, int *real_h_errno, struct __res_state *_res,
  60.               int *_res_socket, int *ExecLib);
  61.  
  62.  
  63. /* A wrapper function for ix_get_vars(). This is not an ixemul function,
  64.  * but it is part of crt0.c. The single argument should be set to 0.
  65.  */
  66. void ix_get_variables(int from_vfork_setup_child);
  67.  
  68.  
  69. /* This is a wrapper intended to make life just a little bit easier for those
  70.  * who need to use the ix_vfork()/ix_vfork_resume() trick.  It replaces the old
  71.  * 'ix_resident()/ix_get_vars()' pair.
  72.  */
  73. void ix_vfork_setup_child(void);
  74.  
  75.  
  76. /* This is an implementation extension to the `real' ix_vfork(). Normally you
  77.  * can only cause the parent to resume by calling _exit() or execve() from
  78.  * the child. Since there is no real fork() in ixemul, this function
  79.  * is a third possibility to make the parent resume. You have then two
  80.  * concurrent processes sharing the same frame and global data. Please be
  81.  * EXTREMELY careful what you may do and what not. ix_vfork() itself is a hack,
  82.  * this is an even greater one...
  83.  *
  84.  * DO NOT use this function in combination with vfork(), or you'll get a big
  85.  * memory leak. Only use it with ix_vfork().
  86.  */
  87. void ix_vfork_resume(void);
  88.  
  89.  
  90. /* This function will show a requester with the given formatted string as
  91.  * the body text and with one or two buttons. If button1 is NULL, then an
  92.  * Abort button is shown. If button1 is not NULL, but button2 is, then only
  93.  * a single button is shown. The title of the requester is passed in the
  94.  * first argument. If that argument is NULL, then ixemul will use the program
  95.  * name instead. Use this function to show a message in an OS independent
  96.  * fashion.
  97.  *
  98.  * The function returns 0 is button1 is pressed and 1 otherwise.
  99.  *
  100.  * Example: ix_req(NULL, "Abort", NULL, "%s only supports AmigaOS!", __progname);
  101.  * choice = ix_req(NULL, "Abort", "Continue", "Cannot find file %s", filename);
  102.  */
  103. int ix_req(char *title, char *button1, char *button2, char *fmt, ...);
  104.  
  105.  
  106. /* Similar to chmod(), but obtains the original OS protection bits.
  107.  * No translation to Unix protection bits has taken place.
  108.  */
  109. int ix_chmod(char *name, int mode);
  110.  
  111.  
  112. /* Like select() but you can pass a pointer to an extra bitmask as the last
  113.  * argument. In that case select() will also wait on these signal bits and
  114.  * return if one of these signals came in. The contents of mask will be set
  115.  * to the signals that arrived.
  116.  */
  117. int ix_select(int nfd, fd_set *ifd, fd_set *ofd, fd_set *efd,
  118.               struct timeval *timeout, long *mask);
  119.  
  120. /* Use ix_wait instead of Wait(): this way ixemul will handle Ctrl-C correctly
  121.  * for you and will also take care of ASYNC file streams, sending a SIGIO
  122.  * signal if something arrives.
  123.  */
  124. #define ix_wait(pmask) ix_select(0, NULL, NULL, NULL, NULL, pmask)
  125.  
  126. /* This function returns the internal OS filehandle for a given ixemul file
  127.  * descriptor. Note that this function can return 0 as not every descriptor
  128.  * is actually a file. Use this function very restrictively: it lets you
  129.  * use OS functions on ixemul descriptors and mixing these two can be a
  130.  * tricky thing.
  131.  */
  132. long ix_filehandle(int fd);
  133.  
  134.  
  135. /* These two functions can be used to walk through all the segments in a
  136.  * segmentlist. These functions are used by gdb using segment list pointers
  137.  * obtained through the ptrace() call. They are generally used like this:
  138.  *
  139.  *      ix_segment *seg;
  140.  *
  141.  *    for (seg = ix_get_first_segment(seglist);
  142.  *           seg;
  143.  *           seg = ix_get_next_segment())
  144.  *      {
  145.  *        .....
  146.  *      }
  147.  */
  148.  
  149. /* These are the possible segment type values
  150.  */
  151. #define IX_SEG_TYPE_UNKNOWN 0
  152. #define IX_SEG_TYPE_TEXT    1
  153. #define IX_SEG_TYPE_DATA    2
  154. #define IX_SEG_TYPE_BSS     3
  155. #define IX_SEG_TYPE_MAX     3
  156.  
  157. /* The segment info is stored in this static (!) structure.
  158.  * So you cannot walk through two segment lists at the same time
  159.  * in the same program.
  160.  */
  161. typedef struct
  162. {
  163.   void *start;
  164.   unsigned long size;
  165.   int type;
  166. } ix_segment;
  167.  
  168.  
  169. /* The function prototypes
  170.  */
  171. ix_segment *ix_get_first_segment(long seglist);
  172. ix_segment *ix_get_next_segment(void);
  173.  
  174.  
  175. /* Flush the instruction cache from the given address with the given
  176.  * length.
  177.  */
  178. void ix_flush_insn_cache(void *addr, int length);
  179.  
  180.  
  181. /* Flush the data cache from the given address with the given
  182.  * length.
  183.  */
  184. void ix_flush_data_cache(void *addr, int length);
  185.  
  186.  
  187. /* Flush all caches completely
  188.  */
  189. void ix_flush_caches(void);
  190.  
  191.  
  192. /* These two function query and set certain properties of ixemul.library.
  193.  * Given a certain ID, ix_get_long will return the corresponding value or
  194.  * -1 if not found. Some IDs may require extra information passed in the 
  195.  * 'extra' argument. Set to 0 unless stated otherwise in the ID
  196.  * description.
  197.  *
  198.  * ix_set_long will set the value of the given ID. It returns -1 if it
  199.  * couldn't set the value and it returns the old value otherwise.
  200.  */
  201. long ix_get_long(unsigned long id, unsigned long extra);
  202. long ix_set_long(unsigned long id, long value);
  203.  
  204. /* Valid IDs: */
  205.  
  206. /* The version number of the library, output only
  207.  */
  208. #define IXID_VERSION          0
  209.  
  210. /* The revision number of the library, output only
  211.  */
  212. #define IXID_REVISION         1
  213.  
  214. /* Get/set the per-task freely usable user field, input/output
  215.  */
  216. #define IXID_USERDATA         2
  217.  
  218. /* Get the pointer to the user struct, output only
  219.  */
  220. #define IXID_USER             3
  221.  
  222. /* Get the number of reserved a4 pointers (for the shared ixlibraries),
  223.  * output only.
  224.  */
  225. #define IXID_A4_PTRS           4
  226.  
  227. /* Return TRUE if an FPU is present
  228.  */
  229. #define IXID_HAVE_FPU           5
  230.  
  231. /* Return CPU identification (see below)
  232.  */
  233. #define IXID_CPU                6
  234.  
  235. /* Return OS identification (see description of ix_os above)
  236.  */
  237. #define IXID_OS                 7
  238.  
  239.  
  240. /* CPU identifications: */
  241. #define IX_CPU_68000        0
  242. #define IX_CPU_68010        1
  243. #define IX_CPU_68020        2
  244. #define IX_CPU_68030        3
  245. #define IX_CPU_68040        4
  246. #define IX_CPU_68060        6
  247.  
  248.  
  249. /* Duplicates and releases the socket "fd" to the TCP/IP stack so
  250.  * other processes can use it. The return value should be used with
  251.  * obtainsocket(). NOTE: The original socket is still valid!
  252.  */
  253. int ix_release_socket(int fdes);
  254.  
  255. /* Gains access to the socket with id "id". id was the return value of
  256.  * releasesocket() and the domain, type, protocol should match the arguments
  257.  * of the socket() call.
  258.  */
  259. int ix_obtain_socket(long id, int inet, int stream, int protocol);
  260.  
  261. /* Structure for OS independent semaphores. The 124 bytes buffer is
  262.  * big enough to store an AmigaOS or a p.OS semaphore and leaves enough
  263.  * room for future expansion.
  264.  *
  265.  * Before using this structure you must ensure that ix_mutex_initialized
  266.  * is 0!
  267.  */
  268. struct ix_mutex
  269. {
  270.   int  ix_mutex_initialized;
  271.   char ix_mutex_buf[124];
  272. };
  273.  
  274.  
  275. /* Lock this mutex. Locks may be nested!
  276.  * Returns 0 if succeeds, -1 if it fails. In case of failure, errno will
  277.  * contain the cause. Currently it never fails, but in the future it may
  278.  * fail and set errno to EINTR.
  279.  */
  280. int ix_mutex_lock(struct ix_mutex *mutex);
  281.  
  282. /* Try to lock this mutex. Locks may be nested!
  283.  * Returns 0 if succeeds, -1 if it fails. In case of failure, errno will
  284.  * contain the cause. If it couldn't lock the mutex, errno will be set to
  285.  * EAGAIN.
  286.  */
  287. int ix_mutex_attempt_lock(struct ix_mutex *mutex);
  288.  
  289. /* Unlock the mutex.
  290.  */
  291. void ix_mutex_unlock(struct ix_mutex *mutex);
  292.  
  293. #if 0
  294. ix_resident
  295. // use ix_geta4 in callbacks installed using funopen() when -resident
  296. ix_geta4
  297. ix_check_cpu
  298. ix_tracecntl
  299. ix_default_wb_window
  300. ix_get_gmt_offset
  301. ix_set_gmt_offset
  302. ix_get_default_settings
  303. ix_get_settings
  304. ix_set_settings
  305. __init_stk_limit
  306. __stkovf
  307. __stkext
  308. __stkext_f
  309. __stkrst
  310. #endif
  311.  
  312. #endif
  313.